package com.my.chapter11;

import java.util.ArrayList;
import java.util.Iterator;

public class practice10 {
    public static void main(String[] args) {
        ArrayList<Rodent> al = new ArrayList<Rodent>();
        al.add(new Rodent());
        al.add(new Mouse());
        al.add(new Gerbils());
        al.add(new Hamster());
        Iterator<Rodent> it = al.iterator();
        while(it.hasNext()){
            Rodent r = it.next();
            r.eat();
        }
    }
}

class Rodent{
    public void eat(){
        System.out.println("啮齿动物吃东西");
    }
}

class Mouse extends Rodent {
    public void eat(){
        System.out.println("老鼠吃东西");
    }
}

class Gerbils extends Rodent {
    public void eat(){
        System.out.println("鼹鼠吃东西");
    }
}

class Hamster extends Rodent {
    public void eat(){
        System.out.println("大颊鼠吃东西");
    }
}

